<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/26
 * Time: 12:19
 */

namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller {

    public function __construct()
    {
        parent::__construct();
    }

    //加载登录主界面
    public function login()
    {
        $this->display();
    }

    //验证登录的正确性
    public function check_login()
    {
        $model = D('admin');
        $user = I('post.user');
        $password = md5(I('post.password'));
        $condition['user'] = $user;
        $data = $model->where($condition)->select();
        if($password==$data[0]['password'])
        {
            $_SESSION['user']=$user;
            $res = array(
                'msg'=>'success',
                'status'=>1
            );
        }else{
            $res = array(
                'msg'=>'failed',
                'status'=>2
            );
        }
        $this->ajaxReturn($res);
    }

    //登出
    public function login_out()
    {
       unset($_SESSION['user']);
        redirect(U('admin.php/login/login'));
    }



}